<%@ page import="com.example.demo_text.CourseDAO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    String courseId = request.getParameter("course_id");
    String courseName = "";
    if (courseId != null && !courseId.isEmpty()) {
        courseName = CourseDAO.getCourseNameById(courseId);
    }

    String tab = request.getParameter("tab");
    if (tab == null || tab.isEmpty()) {
        tab = "chapters";
    }
    
    // 调试输出
    System.out.println("class_space.jsp - tab: " + tab + ", courseId: " + courseId);
%>

<!DOCTYPE html>
<html>
<head>
    <title>课程空间</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', sans-serif;
            background: linear-gradient(135deg, #e0f7fa, #f3e5f5);
            min-height: 100vh;
            margin: 0;
            padding: 0;
        }

        .container {
            width: 100%;
            min-height: 90vh;
            background: white;
            display: flex;
            flex-direction: column;
        }

        .header {
            padding: 20px;
            text-align: center;
            border-bottom: 1px solid #e5e7eb;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .header h2 {
            margin-bottom: 10px;
        }

        .header p {
            color: #6b7280;
            font-size: 14px;
        }

        .main {
            display: flex;
            flex: 1;
        }

        .menu-container {
            width: 150px;
            border-right: 1px solid #e5e7eb;
            padding: 20px;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
        }

        .menu-container h3 {
            margin-bottom: 20px;
        }

        .menu-item {
            padding: 10px 15px;
            margin-bottom: 10px;
            cursor: pointer;
            transition: all 0.3s ease;
            border-radius: 6px;
            display: block;
            text-decoration: none;
            color: inherit;
        }

        .menu-item:hover,
        .menu-item.active {
            background-color: #d1ecf1;
            color: #15576b;
            text-decoration: none;
        }

        .content {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
        }

        .footer {
            padding: 15px;
            text-align: center;
            border-top: 1px solid #e5e7eb;
            background-color: #f9fafb;
            width: 100%;
        }

        .btn-back {
            display: inline-block;
            padding: 12px 24px;
            background-color: #f3f4f6;
            color: #374151;
            border-radius: 8px;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
        }

        .btn-back:hover {
            background-color: #d1d5db;
            color: #111827;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        /* 响应式适配 */
        @media screen and (max-width: 768px) {
            .main {
                flex-direction: column;
            }

            .menu-container {
                width: 100%;
                border-right: none;
                border-bottom: 1px solid #e5e7eb;
            }
        }
    </style>
</head>
<body>

<div class="container">
    <!-- 页面顶部（课程空间） -->
    <div class="header">
        <h2>课程空间</h2>
        <p>当前课程名称：<%= courseName %></p>
    </div>

    <!-- 主体部分 -->
    <div class="main">
        <!-- 功能菜单 -->
        <div class="menu-container">
            <h3>功能菜单</h3>
            <a href="class_space.jsp?tab=chapters&course_id=<%= courseId %>" class="menu-item <%= "chapters".equals(tab) ? "active" : "" %>">章节</a>
            <a href="class_space.jsp?tab=discussions&course_id=<%= courseId %>" class="menu-item <%= "discussions".equals(tab) ? "active" : "" %>">讨论</a>
            <a href="class_space.jsp?tab=assignments&course_id=<%= courseId %>" class="menu-item <%= "assignments".equals(tab) ? "active" : "" %>">作业</a>
            <a href="class_space.jsp?tab=exams&course_id=<%= courseId %>" class="menu-item <%= "exams".equals(tab) ? "active" : "" %>">考试</a>
        </div>

        <!-- 右侧内容区域 -->
        <div class="content">
            <% if ("chapters".equals(tab)) { %>
                <jsp:include page="chapters.jsp">
                    <jsp:param name="course_id" value="<%= courseId %>"/>
                </jsp:include>
            <% } else if ("discussions".equals(tab)) { %>
                <jsp:include page="discussions.jsp">
                    <jsp:param name="course_id" value="<%= courseId %>"/>
                </jsp:include>
            <% } else if ("assignments".equals(tab)) { %>
                <jsp:include page="assignments.jsp">
                    <jsp:param name="course_id" value="<%= courseId %>"/>
                </jsp:include>
            <% } else if ("exams".equals(tab)) { %>
                <jsp:include page="exams.jsp">
                    <jsp:param name="course_id" value="<%= courseId %>"/>
                </jsp:include>
            <% } %>
        </div>
    </div>

    <!-- 页面底部（返回我的课程） -->
    <div class="footer">
        <a href="my_class.jsp" class="btn-back">返回我的课程</a>
    </div>
</div>

</body>
</html>
